<template>
  <div>
    <el-button @click="submit1">防抖</el-button>
    
    <el-button @click="submit2">节流</el-button>
    
  </div>
</template>

<script>
// 公共方法
// 防抖
 function debounce(func,wait = 500){
   let timeout;
   return function(event){
      if(timeout !== null) clearTimeout(timeout)
        timeout = setTimeout(()=>{
          func.call(this,event)
        }, wait)
   }
 }

 // 节流
 function throttleT(fn, wait = 500) {
            let timeout;
            return function () {
                let context = this
                let arg = arguments
                if (!timeout) {
                    timeout = setTimeout(() => {
                        timeout = null
                        fn.apply(context, [arg])
                    }, wait)
                }
            }
        }

export default {
  data() {
    return {
    };
  },
  methods: {
    
    submit1:debounce(function(){
      console.log("操作1");
    }),
    submit2:throttleT(function(){
     console.log("操作2");
    })
  },
};
</script>